package result;

import lombok.Data;
/**
 * 通用返回结果，服务端响应的数据最终都会封装成此对象
 * @param <T>
 */
@Data
public class Result<T> {

    private Integer code; //编码：200成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 200;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }

    public static <T> Result<T> error(String msg, Integer code) {
        Result result = new Result();
        result.msg = msg;
        result.code = code;
        return result;
    }
}
